home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-02-18 | 21.9 KB | 850 lines | [TEXT/MPS ] |
- /*
- File: Utilities.c
-
- Contains: Location Manager SDK Sample Module handy routines
-
- Version: ALM SDK 1.0
- Package: Location Manager SDK 1.0
-
- Copyright: © 1984-1997 by Apple Computer, Inc.
- All rights reserved.
-
- Bugs?: If you find a problem with this file, use the Apple Bug Reporter
- stack. Include the file and version information (from above)
- in the problem description and send to:
- Internet: apple.bugs@apple.com
-
- */
-
- // -------------------------------------------------------------------------------------
-
- // Module Includes...
-
- #ifndef __UTILITIES__
- #include "Utilities.h"
- #endif // __UTILITIES__
-
- // Project Includes...
-
- #ifndef __SAMPLE__
- #include "Sample.h"
- #endif // __SAMPLE__
-
- // MacOS Includes...
-
- #ifndef __FOLDERS__
- #include <Folders.h>
- #endif // __FOLDERS__
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif // __GESTALT__
-
- #ifndef __LOWMEM__
- #include <LowMem.h>
- #endif // __LOWMEM__
-
- #ifndef __PLSTRINGFUNCS__
- #include <PLStringFuncs.h>
- #endif // __PLSTRINGFUNCS__
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif // __RESOURCES__
-
- #ifndef __SCRIPT__
- #include <Script.h>
- #endif // __SCRIPT__
-
- // ANSI Includes...
-
- #include <string.h>
-
- // -------------------------------------------------------------------------------------
-
- // Readability Constants...
-
- #define kInvalidRefNum (-1)
- #define kUseSetting false
- #define kReadSetting true
- #define kNoIdleProc NULL
- #define kNoFilterProc NULL
- #define kTimeToQuit (10*60) // 10 seconds to quit...
- #define kDontUseIndex 0
- #define kNoFileName "\p"
-
- // Expressive Macros...
-
- #define ShareTime() { EventRecord e; WaitNextEvent (0, &e, 1, NULL); }
- #define EmptyAEDesc(desc) { desc.descriptorType = typeNull; \
- desc.dataHandle = NULL; }
- #define SetFirstProcess(psn) { psn.highLongOfPSN = 0; \
- psn.lowLongOfPSN = kNoProcess; }
-
- // -------------------------------------------------------------------------------------
-
- // Local prototypes...
-
- static OSErr
- QuitApplications (Boolean readOnly);
- // Quit applications if appropriate
- static OSErr
- SendQuitApplication (Boolean* wasOpen, OSType creator);
- // Send a "quit" AppleEvent to the application whose creator is given...
- static Boolean
- FindProcessByCreator (ProcessSerialNumber* psn, OSType creator);
- // Given a creator code, return the process serial number of the first matching
- // process...
- static Boolean
- ProcessManagerAvailable (void);
- // Good way to tell if it's INIT time...
- static Boolean
- ProcessBecameInvalid (ProcessSerialNumber* psn, UInt32 timeoutInTicks);
- // Little routine to wait for a process to quit (since we can't wait for a reply
- // event)...
- static OSErr
- MakeAnFSSpec (SInt16 idx, SInt16 vRefNum, SInt32 parID, FSSpec* theSpec);
- // Given a (1-based) index, a volume, and a parent directory ID, go out the
- // resource fork, get the corresponding name, and make an FSSpec for it; do
- // not return fnfErr for non-existant files...
- static OSErr
- FSpSwapFile (FSSpecPtr theFile, UInt32 fileIdx, SettingPtr theSetting,
- ALMRebootFlags* flags);
- // Retrieve the file specified by fileIdx (0-based) from theSetting, and, using the
- // FSSpec, adjust the file...
- static OSErr
- FSpAddFile (FSSpecPtr theFile, UInt32 fileIdx, SettingHandle setting,
- UInt32* nextByteToUse);
- // Add the forks of the file specified by fileIndex (0-based) to the setting, starting at
- // offset *nextByteToUse, and adjusting *nextByteToUse to the end of the file; also
- // adjust the corresponding info record...
- static OSErr
- FSpGetFileDates (FSSpecPtr theFile, UInt32* createDate, UInt32* modDate);
- // Given a file, return its creation date and modification date...
- static OSErr
- FSpSetFileDates (FSSpecPtr theFile, UInt32 createDate, UInt32 modDate);
- // Set the creation and modification dates on the specified file...
- static OSErr
- NewTempFile (FSSpec* theFile);
- // Create a temporary file, returning its spec...
-
- // -------------------------------------------------------------------------------------
-
- extern OSErr
- UseSetting (GlobalsHandle globals, SettingHandle setting, ALMRebootFlags* flags) {
-
- OSErr err = ConfirmFSSpecs (globals);
- SInt8 svState = HGetState ((Handle) globals);
-
- HLock ((Handle) globals);
-
- if (err == noErr) {
- err = QuitApplications (kUseSetting);
- } // if
-
- if (err == noErr) {
-
- GlobalsPtr theGlobals = *globals;
- UInt32 fileCount = theGlobals->fileCount;
- UInt32 fileIdx;
- SInt8 setState = HGetState ((Handle) setting);
-
- // Go through and swap each file's data...
-
- if ((**setting).version == kSettingVersion) {
- HLock ((Handle) setting);
- for (fileIdx = 0; fileIdx < fileCount; fileIdx += 1) {
- err = FSpSwapFile (&theGlobals->theFiles[fileIdx], fileIdx, *setting, flags);
- if (err != noErr) {
- break;
- } // if
- } // for
- } else {
- err = paramErr;
- } // if
-
- HSetState ((Handle) setting, setState);
-
- } // if
-
- HSetState ((Handle) globals, svState);
-
- return err;
-
- } // UseSetting
-
- // -------------------------------------------------------------------------------------
-
- extern OSErr
- ReadSetting (GlobalsHandle globals, SettingHandle setting) {
-
- OSErr err = ConfirmFSSpecs (globals);
- SInt8 svState = HGetState ((Handle) globals);
-
- HLock ((Handle) globals);
-
- if (err == noErr) {
- err = QuitApplications (kReadSetting);
- } // if
-
- if (err == noErr) {
-
- GlobalsPtr theGlobals = *globals;
- UInt32 fileCount = theGlobals->fileCount;
- UInt32 fileIdx;
- UInt32 freeDataOffset;
-
- // First make room for the fixed-size records; we'll add space for each
- // file's data later...
-
- if (fileCount > 0) {
-
- freeDataOffset = sizeof (SettingRec) +
- sizeof (FileInfoRec) * (fileCount - kVariableLengthArray);
- SetHandleSize ((Handle) setting, freeDataOffset);
- err = MemError ();
-
- // Go through and add each file's data...
-
- if (err == noErr) {
- (**setting).fileCount = 0;
- (**setting).version = kSettingVersion;
- for (fileIdx = 0; fileIdx < fileCount; fileIdx += 1) {
- err = FSpAddFile (&theGlobals->theFiles[fileIdx], fileIdx, setting, &freeDataOffset);
- if (err != noErr) {
- break;
- } // if
- (**setting).fileCount = fileIdx + 1;
- } // for
- } // if
-
- } // if
-
- } // if
-
- HSetState ((Handle) globals, svState);
-
- return err;
-
- } // ReadSetting
-
- // -------------------------------------------------------------------------------------
-
- extern OSErr
- ConfirmFSSpecs (GlobalsHandle globals) {
-
- OSErr err = noErr;
- SInt8 svState = HGetState ((Handle) globals);
-
- // Our assumption is that if the fileCount is 0, we need to go out and
- // create FSSpecs for the files...
-
- if ((**globals).fileCount == 0) {
-
- SInt16 fileCount;
-
- HUnlock ((Handle) globals); // May need to resize...
-
- // Each file occupies two resources; one is a string, and the other is
- // a bunch of flags (it's done this way to avoid some messy variable-size
- // data), but we only need the string at this point...
-
- fileCount = Count1Resources (kFilesRsrcType);
-
- if (fileCount > 0) {
-
- SInt16 vRefNum;
- SInt32 parID;
- GlobalsPtr theGlobals;
-
- // Prepare the globals to receive our data, and look up the preferences
- // folder just this once...
-
- SetHandleSize ((Handle) globals,
- sizeof (Globals) + sizeof (FSSpec) * (fileCount - kVariableLengthArray));
- err = MemError ();
- if (err == noErr) {
- (**globals).fileCount = fileCount;
- err = FindFolder (kOnSystemDisk, kPreferencesFolderType,
- kDontCreateFolder, &vRefNum, &parID);
- } // if
-
- // With all that, we can lock down the globals, and stuff FSSpecs into
- // the array one at a time...
-
- if (err == noErr) {
-
- SInt16 curFileIdx;
-
- HLock ((Handle) globals);
-
- theGlobals = *globals;
-
- for (curFileIdx = 0; curFileIdx < fileCount; curFileIdx += 1) {
-
- err = MakeAnFSSpec (curFileIdx + 1, vRefNum, parID,
- &theGlobals->theFiles[curFileIdx]);
- if (err != noErr) {
- break;
- } // if
-
- } // for
-
- } // if
-
- } // if
-
- } // if
-
- HSetState ((Handle) globals, svState);
-
- return err;
-
- } // ConfirmFSSpecs
-
- // -------------------------------------------------------------------------------------
-
- extern void
- InsParamStr (StringPtr matchThis, StringPtr replaceWithThis, StringPtr replaceInThis) {
-
- UInt8 matchLen = StrLength (matchThis);
- UInt8 replaceLen = StrLength (replaceWithThis);
- UInt8 replaceInLen = StrLength (replaceInThis);
- Ptr matchPtr;
- Str255 tempStr;
-
- matchPtr = PLstrstr (replaceInThis, matchThis);
- PLstrcpy (tempStr, replaceInThis);
-
- if (matchPtr != NULL) {
-
- UInt8 matchPos = (UInt32) matchPtr - (UInt32) replaceInThis;
- UInt8 contPos = matchPos + matchLen;
- UInt8 frontLen = matchPos - 1;
- UInt8 backLen = replaceInLen - frontLen - matchLen;
-
- BlockMoveData (&replaceWithThis[1], &replaceInThis[matchPos], replaceLen);
- BlockMoveData (&tempStr[contPos], &replaceInThis[frontLen + replaceLen + 1], backLen);
- replaceInThis[0] = ((UInt32) replaceInLen - (UInt32) matchLen + (UInt32) replaceLen);
-
- } // if
-
- } // InsParamStr
-
- // -------------------------------------------------------------------------------------
-
- static OSErr
- QuitApplications (Boolean readOnly) {
-
- OSErr err = noErr;
- ApplicationListHandle appsHandle;
-
- appsHandle = (ApplicationListHandle) Get1Resource (kAppsRsrcType, kAppsRsrcID);
-
- if (appsHandle != NULL) {
-
- UInt32 curApp;
- ApplicationListPtr apps;
- UInt8 flags;
- Boolean wasOpen;
-
- HLock ((Handle) appsHandle);
- apps = *appsHandle;
-
- for (curApp = 0; curApp < apps->applicationCount; curApp += 1) {
- flags = apps->applications[curApp].flags;
- if ((flags == kAppListQuitOnGetOrSet) ||
- (readOnly && (flags == kAppListQuitOnGet)) ||
- (!readOnly && (flags == kAppListQuitOnSet))) {
- err = SendQuitApplication (&wasOpen, apps->applications[curApp].applicationCode);
- if (err != noErr) {
- break;
- } // if
- } // if
- } // for
-
- HUnlock ((Handle) appsHandle);
- ReleaseResource ((Handle) appsHandle);
-
- } else {
-
- err = resNotFound;
-
- } // if
-
- return err;
-
- } // QuitApplications
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- SendQuitApplication (Boolean* wasOpen, OSType creator) {
-
- OSErr err = noErr;
- ProcessSerialNumber applicationPSN;
- AEAddressDesc applicationAddr;
- AppleEvent quitEvent;
- AppleEvent theReply;
-
- EmptyAEDesc (applicationAddr);
- EmptyAEDesc (quitEvent);
- EmptyAEDesc (theReply);
-
- // Find a process matching the creator, if any; if it is found, send it an
- // AppleEvent to quit (it does support the core suite, right?)...
-
- *wasOpen = FindProcessByCreator (&applicationPSN, creator);
-
- if (*wasOpen) {
- if (err == noErr) {
- err = AECreateDesc (typeProcessSerialNumber, &applicationPSN,
- sizeof (applicationPSN), &applicationAddr);
- } // if
- if (err == noErr) {
- err = AECreateAppleEvent (kCoreEventClass, kAEQuitApplication,
- &applicationAddr, kAutoGenerateReturnID, kAnyTransactionID,
- &quitEvent);
- } // if
- if (err == noErr) {
- err = AESend (&quitEvent, &theReply, kAENoReply | kAENeverInteract,
- kAEHighPriority, kAEDefaultTimeout, kNoIdleProc,
- kNoFilterProc);
- } // if
- if (err == noErr) {
- if (!ProcessBecameInvalid (&applicationPSN, kTimeToQuit)) {
- err = kSampleCouldNotQuitIdx; // We'll tell the user we tried...
- } // if
- } // if
- } // if
-
- (void) AEDisposeDesc (&applicationAddr);
- (void) AEDisposeDesc (&quitEvent);
-
- return err;
-
- } // SendQuitApplication
-
- // ------------------------------------------------------------------------------------
-
- static Boolean
- FindProcessByCreator (ProcessSerialNumber* psn, OSType creator) {
-
- OSErr err = noErr;
- Boolean found = false;
- ProcessInfoRec curProcessInfo;
- ProcessSerialNumber curPSN;
-
- SetFirstProcess (curPSN);
-
- // If we're running at INIT time, none of this will work (and we don't need to
- // do it anyway!), so
-
- if (ProcessManagerAvailable ()) {
-
- do {
- curProcessInfo.processInfoLength = sizeof (curProcessInfo);
- curProcessInfo.processName = NULL;
- curProcessInfo.processAppSpec = NULL;
- if (err == noErr) {
- err = GetNextProcess (&curPSN);
- } // if
- if (err == noErr) {
- err = GetProcessInformation (&curPSN, &curProcessInfo);
- } // if
- if (err == noErr) {
- if (curProcessInfo.processSignature == creator) {
- *psn = curPSN;
- found = true;
- break;
- } // if
- } // if
- } while (err == noErr);
-
- } // if
-
- return found;
-
- } // FindProcessByCreator
-
- // ------------------------------------------------------------------------------------
-
- static Boolean
- ProcessManagerAvailable (void) {
-
- OSErr err;
- SInt32 response;
- Boolean reply;
-
- err = Gestalt (gestaltOSAttr, &response);
-
- reply = (err == noErr) && (response & (1 << gestaltLaunchControl));
-
- return reply;
-
- } // ProcessManagerAvailable
-
- // ------------------------------------------------------------------------------------
-
- static Boolean
- ProcessBecameInvalid (ProcessSerialNumber* psn, UInt32 timeoutInTicks) {
-
- OSErr err = noErr;
- Boolean stillAround = true;
- UInt32 startTime = LMGetTicks ();
- UInt32 curTime = startTime;
- UInt32 endTime = startTime + timeoutInTicks;
- ProcessInfoRec processInfo;
-
- // Wait around, being background friendly, for the specified process to
- // terminate...
-
- do {
- ShareTime ();
- if (err == noErr) {
- processInfo.processInfoLength = sizeof (processInfo);
- processInfo.processName = NULL;
- processInfo.processAppSpec = NULL;
- err = GetProcessInformation (psn, &processInfo);
- if ((err == paramErr) || (err == procNotFound)) {
- stillAround = false;
- break;
- } // if
- } // if
- curTime = LMGetTicks ();
- } while (curTime < endTime);
-
- return !stillAround;
-
- } // ProcessBecameInvalid
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- MakeAnFSSpec (SInt16 idx, SInt16 vRefNum, SInt32 parID, FSSpec* theSpec) {
-
- OSErr err = noErr;
- FileEntryHandle fileName;
-
- fileName = (FileEntryHandle) Get1IndResource (kFilesRsrcType, idx);
-
- if (fileName != NULL) {
- HLock ((Handle) fileName);
- err = FSMakeFSSpec (vRefNum, parID, (StringPtr) *fileName, theSpec);
- if (err == fnfErr) {
- err = noErr;
- } // if
- HUnlock ((Handle) fileName);
- ReleaseResource ((Handle) fileName);
- } else {
- err = resNotFound;
- } // if
-
- return err;
-
- } // MakeAnFSSpec
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- FSpSwapFile (FSSpecPtr theFile, UInt32 fileIdx, SettingPtr theSetting,
- ALMRebootFlags* flags) {
-
- OSErr err = noErr;
- FSSpec tempFile;
- SInt16 dataForkRef = kInvalidRefNum;
- SInt16 resForkRef = kInvalidRefNum;
- Ptr dataForkStart;
- Ptr resForkStart;
- SInt32 dataForkLen;
- SInt32 resForkLen;
- FSSpec destSpec;
-
- // Our strategy here is to create a temp file, put our data in it, close the file,
- // swap it with the real one (if the real one exists), then reset the creation and
- // modification dates....
-
- // Create a temp file and open its forks...
-
- if (err == noErr) {
- err = NewTempFile (&tempFile);
- } // if
- if (err == noErr) {
- err = FSpOpenDF (&tempFile, fsRdWrPerm, &dataForkRef);
- } // if
- if (err == noErr) {
- err = FSpOpenRF (&tempFile, fsRdWrPerm, &resForkRef);
- } // if
-
- // Write the data out of the setting...
-
- dataForkStart = ((Ptr) theSetting) + theSetting->fileInfo[fileIdx].dataForkOffset;
- resForkStart = ((Ptr) theSetting) + theSetting->fileInfo[fileIdx].resForkOffset;
- dataForkLen = theSetting->fileInfo[fileIdx].dataForkLen;
- resForkLen = theSetting->fileInfo[fileIdx].resForkLen;
-
- if (err == noErr) {
- err = FSWrite (dataForkRef, &dataForkLen, dataForkStart);
- } // if
- if (err == noErr) {
- err = FSWrite (resForkRef, &resForkLen, resForkStart);
- } // if
-
- // Swap the files (or move the one, if the other does not exist)...
-
- if (err == noErr) {
- err = FSpExchangeFiles (theFile, &tempFile);
- if (err == noErr) {
- err = FSpDelete (&tempFile);
- } else if (err == fnfErr) {
- err = FSMakeFSSpec (theFile->vRefNum, theFile->parID, kNoFileName, &destSpec);
- if (err == noErr) {
- err = FSpCatMove (&tempFile, &destSpec);
- } // if
- } // if
- } // if
-
- // Restore the file's dates...
-
- if (err == noErr) {
- err = FSpSetFileDates (theFile, theSetting->fileInfo[fileIdx].dateCreated,
- theSetting->fileInfo[fileIdx].dateModified);
- } // if
-
- // Now, the fiddly part--using the index, get the reboot flags for this file...
-
- if (err == noErr) {
-
- // We'll do it this "roundabout" way so that we know we're correctly matching
- // resource ids...
-
- FileEntryHandle fileName = (FileEntryHandle) Get1IndResource (kFilesRsrcType, fileIdx + 1);
- SInt16 rsrcID;
- ResType rsrcType;
- Str255 rsrcName;
- FileFlagsHandle theFlags;
-
- if (fileName != NULL) {
-
- GetResInfo ((Handle) fileName, &rsrcID, &rsrcType, rsrcName);
- err = ResError ();
- if (err == noErr) {
- theFlags = (FileFlagsHandle) Get1Resource (kRestartRsrcType, rsrcID);
- if ((**theFlags).flags & kRestartIfChanged != 0) {
- *flags = kALMExtensions;
- } // if
- ReleaseResource ((Handle) theFlags);
- } // if
- ReleaseResource ((Handle) fileName);
-
- } else {
- err = resNotFound;
- } // if
-
- } // if
-
- // Cleanup...
-
- if (dataForkRef != kInvalidRefNum) {
- (void) FSClose (dataForkRef);
- } // if
- if (resForkRef != kInvalidRefNum) {
- (void) FSClose (resForkRef);
- } // if
-
- return err;
-
- } // FSpSwapFile
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- FSpAddFile (FSSpecPtr theFile, UInt32 fileIdx, SettingHandle setting,
- UInt32* nextByteToUse) {
-
- OSErr err = noErr;
- SInt16 dataForkRef = kInvalidRefNum;
- SInt16 resForkRef = kInvalidRefNum;
- SInt32 dataForkLen;
- SInt32 resForkLen;
- SInt8 svState = HGetState ((Handle) setting);
- SInt32 newHandleSize;
- UInt32 freeDataOffset = *nextByteToUse;
- UInt32 createDate;
- UInt32 modDate;
-
- // Open both forks (no dining philosophers, please), and get the Dates...
-
- if (err == noErr) {
- err = FSpGetFileDates (theFile, &createDate, &modDate);
- } // if
- if (err == noErr) {
- err = FSpOpenDF (theFile, fsRdPerm, &dataForkRef);
- } // if
- if (err == noErr) {
- err = FSpOpenRF (theFile, fsRdPerm, &resForkRef);
- } // if
-
- // Determine how long the forks are...
-
- if (err == noErr) {
- err = GetEOF (dataForkRef, &dataForkLen);
- } // if
- if (err == noErr) {
- err = GetEOF (resForkRef, &resForkLen);
- } // if
-
- // Resize the handle so we can store the data in it, then lock it down for reading...
-
- if (err == noErr) {
- newHandleSize = freeDataOffset + dataForkLen + resForkLen;
- SetHandleSize ((Handle) setting, newHandleSize);
- err = MemError ();
- } // if
- if (err == noErr) {
-
- SettingPtr theSetting;
- FileInfoPtr theFileInfo;
- Ptr startAddr;
-
- HLock ((Handle) setting);
-
- theSetting = *setting;
- theFileInfo = &theSetting->fileInfo[fileIdx];
- startAddr = ((Ptr) theSetting) + freeDataOffset;
-
- // Record information about the file
-
- theFileInfo->dateCreated = createDate;
- theFileInfo->dateModified = modDate;
- theFileInfo->dataForkOffset = freeDataOffset;
- theFileInfo->dataForkLen = dataForkLen;
- theFileInfo->resForkOffset = freeDataOffset + dataForkLen;
- theFileInfo->resForkLen = resForkLen;
-
- // Finally, read in the forks at their alloted locations...
-
- if ((err == noErr) && (dataForkLen > 0)) {
- err = FSRead (dataForkRef, &dataForkLen, startAddr);
- } // if
- if ((err == noErr) && (resForkLen > 0)) {
- err = FSRead (resForkRef, &resForkLen, startAddr + dataForkLen);
- } // if
-
- } // if
-
- // Cleanup...
-
- if (dataForkRef != kInvalidRefNum) {
- (void) FSClose (dataForkRef);
- } // if
- if (resForkRef != kInvalidRefNum) {
- (void) FSClose (resForkRef);
- } // if
-
- *nextByteToUse = newHandleSize;
-
- HSetState ((Handle) setting, svState);
-
- return err;
-
- } // FSpAddFile
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- FSpGetFileDates (FSSpecPtr theFile, UInt32* createDate, UInt32* modDate) {
-
- OSErr err = noErr;
-
- if (err == noErr) {
-
- HParamBlockRec paramBlock;
- HFileParam* fileParam = ¶mBlock.fileParam;
-
- fileParam->ioCompletion = NULL;
- fileParam->ioNamePtr = (StringPtr) theFile->name;
- fileParam->ioVRefNum = theFile->vRefNum;
- fileParam->ioFDirIndex = kDontUseIndex;
- fileParam->ioDirID = theFile->parID;
-
- err = PBHGetFInfoSync (¶mBlock);
-
- if (err == fnfErr) {
- *createDate = 0;
- *modDate = 0;
- err = noErr;
- } else {
- *createDate = fileParam->ioFlCrDat;
- *modDate = fileParam->ioFlMdDat;
- } // if
-
- } // if
-
- return err;
-
- } // FSpGetFileDates
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- FSpSetFileDates (FSSpecPtr theFile, UInt32 createDate, UInt32 modDate) {
-
- OSErr err = noErr;
-
- if (err == noErr) {
-
- HParamBlockRec paramBlock;
- HFileParam* fileParam = ¶mBlock.fileParam;
-
- fileParam->ioCompletion = NULL;
- fileParam->ioNamePtr = (StringPtr) theFile->name;
- fileParam->ioVRefNum = theFile->vRefNum;
- fileParam->ioFDirIndex = kDontUseIndex;
- fileParam->ioDirID = theFile->parID;
-
- err = PBHGetFInfoSync (¶mBlock);
-
- if (err == noErr) {
- // Need to restore PBHGetFInfoSync because it changes ioDirID to a fileID
- // but we want the dirID for the PBHSetFInfoSync call to work!
- fileParam->ioDirID = theFile->parID;
- fileParam->ioFlCrDat = createDate;
- fileParam->ioFlMdDat = modDate;
- err = PBHSetFInfoSync (¶mBlock);
- } // if
-
- } // if
-
- return err;
-
- } // FSpSetFileDates
-
- // ------------------------------------------------------------------------------------
-
- static OSErr
- NewTempFile (FSSpec* theFile) {
-
- OSErr err = noErr;
- SInt16 vRefNum;
- SInt32 parID;
-
- if (err == noErr) {
-
- err = FindFolder (kOnSystemDisk, kTemporaryFolderType, kCreateFolder,
- &vRefNum, &parID);
- if (err == noErr) {
- err = FSMakeFSSpec (vRefNum, parID, "\pModule Temp", theFile);
- if (err == noErr) {
- err = dupFNErr;
- } else if (err == fnfErr) {
- err = FSpCreate (theFile, '\?\?\?\?', '\?\?\?\?', smSystemScript);
- } // if
- } // if
-
- } // if
-
- return err;
-
- } // NewTempFile
-